//
//  ZpStatusListViewModel.m
//  WeiBo_OC
//
//  Created by MacBook Pro on 16/5/30.
//  Copyright © 2016年 MacBook Pro. All rights reserved.
//

#import "ZpStatusListViewModel.h"
#import "ZpNetWorkTool.h"
#import "ZpUserAccount.h"
#import "ZpStatus.h"
@interface ZpStatusListViewModel ()
@property (nonatomic, strong) ZpNetWorkTool *netTool;
@property (nonatomic, strong) ZpUserAccount *account;

@end
@implementation ZpStatusListViewModel

- (instancetype)init{

    if (self = [super init]) {
        _netTool = [ZpNetWorkTool shareNetWorkTool];
        _account = [ZpUserAccount shareUserAccount];
    }
    
    return self;
}

- (void)sendReuqestForStatus:(void(^)())block{
    
    NSString *urlString = [NSString stringWithFormat:@"%@%@", self.netTool.info.host, self.netTool.info.status];
    NSDictionary *parameters = @{
         @"access_token" :  self.account.access_token,
         };
    NSLog(@"%@", self.account.access_token);
    [self.netTool sendHttpRequestWithMethod:GET andParameters:parameters andURLString:urlString andfinshed:^(NSData *data, NSError *error) {
        if (error) {
            NSLog(@"无法获取微博数据");
            return;
        }
        
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
        NSArray *arrs = dict[@"statuses"];
        
        NSMutableArray *arrM = [NSMutableArray array];
        for(NSDictionary *dict in arrs){
            
            ZpStatusViewModel *svm = [[ZpStatusViewModel alloc] initWithDict:dict];
            [arrM addObject:svm];
        }
        self.statusViewModel = arrM;
        block();
    }];
}
@end
